 /*
 * @description: 意见反馈/用户反馈
 * @Author: along
 * @Date: 2020-09-14
 * @Last Modified by: along
 * @Last Modified time: 2020-09-14
 */
<template>
    <div class="container feedBackUser">
        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">ID或手机号:</p>
                    <el-input
                        v-model="filterData.keyword_student_id"
                        placeholder="请输入用户ID或手机号"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">反馈渠道:</p>
                    <el-select
                        v-model="filterData.type"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in typeList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"/>
                    </el-select>
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            class="data-table"
            ref="feedBackUser"
        >
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="student_info.true_name"
                label="用户姓名"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="student_info.student_no"
                label="用户ID"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="150"
            />
            <el-table-column
                prop="student_info.phone"
                label="手机号"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="150"
            />
            <el-table-column
                prop="school_name"
                label="学校名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                :width="160"
            >
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        v-if="scope.row.student_info.school_name"
                        @click="copyUrl(scope.row.student_info.school_name)"
                    >
                        {{ scope.row.student_info.school_name }}
                    </el-button>
                    <div v-else>--</div>
                </template>
            </el-table-column>
            <!--<el-table-column
                prop="type"
                label="反馈类型"
                show-overflow-tooltip
                :formatter="typeFormatter"
                align="left"
            />
            <el-table-column
                prop="hire_info.company_name"
                label="反馈企业"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="aim_title"
                min-width="100"
                label="反馈标题"
                show-overflow-tooltip
                align="left"
            >
                <template slot-scope="scope">
                    <div v-if="scope.row.aim_title !== ''">
                        <el-popover
                            trigger="click"
                            placement="top"
                        >
                            <div class="preview-body">
                                <div
                                    class="title"
                                    :style="{width: '100%', textAlign: 'center', marginBottom: '5px'}"
                                >扫码预览页面</div>
                                <div
                                    class="code"
                                    v-loading="!scope.row.preview_code">
                                    <img
                                        :src="scope.row.preview_code"
                                        :style="{width:'150px', height: '150px'}"
                                    >
                                </div>
                            </div>
                            <div
                                class="aim-title ellipsis cursor-font"
                                @click="fnGetCode(scope.row)"
                                slot="reference"
                            >
                                {{ scope.row.aim_title }}
                            </div>
                        </el-popover>
                    </div>
                    <div v-else>&#45;&#45;</div>
                </template>
            </el-table-column>-->
            <el-table-column
                :formatter="emptyFormatter"
                prop="content"
                show-overflow-tooltip
                label="反馈内容"
                align="left"
                :width="150"
            />
            <el-table-column
                label="反馈渠道"
                :width="150"
            >
                <template slot-scope="scope">
                    {{ scope.row.type | typeFilter }}
                </template>
            </el-table-column>
            <el-table-column
                prop="finish_percent"
                label="反馈图片"
                align="left"
            >
                <template slot-scope="scope">
                    <template v-if="scope.row.images.length > 0">
                        <a
                            href="javascript:;"
                            style="color: #409EFF"
                            @click="fnShowPreview(scope.row.images)">查看({{ scope.row.images.length }})</a>
                    </template>
                    <template v-else>
                        --
                    </template>
                </template>
            </el-table-column>
            <el-table-column
                prop="create_time"
                :formatter="emptyFormatter"
                label="反馈时间"
                align="left"
                :width="150"
            >
                <template slot-scope="scope">
                    <template v-if="scope.row.create_time">{{ scope.row.create_time*1000 | dateFormatter('yyyy/MM/dd HH:mm') }}</template>
                    <template v-else>--</template>
                </template>
            </el-table-column>
            <el-table-column
                label="反馈回复"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.reply_content }}
                </template>
            </el-table-column>
            <el-table-column
                :formatter="emptyFormatter"
                prop="remark"
                show-overflow-tooltip
                label="反馈备注"
                align="left"
                :width="150"
            />
            <el-table-column
                label="操作"
                align="center"
                fixed="right"
            >
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        class="curse-add"
                        @click="reReplytoUser(scope.row)"
                    >
                        回复用户
                    </el-button>
                    <el-button
                        type="text"
                        class="curse-add"
                        @click="fnRemark(scope.row)"
                    >
                        备注
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>

        <!-- 图片预览 -->
        <img-preview ref="preview" />
    </div>
</template>

<script>
import imgPreview from '@/components/common/img-preview';
import { back } from '@/mixin/back';
export default {
    mixins: [back],
    components: {
        imgPreview
    },
    data () {
        return {
            authResult: {},
            typeList: [
                {value: 99,label: '全部'},
                {value: 7,label: '学生认证'},
                {value: 0,label: '意见反馈'},
            ],
            tableData: [],
            filterData: {
                type: 99,
                keyword_student_id: ''
            },
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
        };
    },
    filters: {
        typeFilter(val) {
            switch (val) {
                case 0:
                    return '意见反馈';
                case 1:
                    return '商品';
                case 2:
                    return '任务';
                case 3:
                    return '校园大使';
                case 4:
                    return '兼职';
                case 5:
                    return '实习';
                case 6:
                    return '社区班级';
                case 7:
                    return '学生认证';
                default:
                    return '--';
            }
        },
    },
    computed: {},
    watch: {},
    mounted () {
        this.authResult = this.$route.meta.authResult;
        this.$store.commit('SET_HEADER', [{title: "APP后台",},{title: '意见反馈'},{title: '用户反馈'}]);

        const query = this.$route.query;

        if(query.keyword_student_id !== undefined) {
            this.filterData.keyword_student_id = query.keyword_student_id;
        }

        this.getTableData();
    },
    methods: {
        /**
         * @description 获取表格数据
         */
        getTableData(page) {
            let { type, keyword_student_id } = this.filterData;

            this.$post('/student/student_complain%5Cget_list', {
                page_id: page || this.page.now_page,
                type,
                keyword_student_id
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                    if (resp.data.page.total_page > 0 && resp.data.page.total_page < resp.data.page.now_page) {
                        this.getTableData(resp.data.page.total_page);
                    }
                }
            });
        },

        /**
         * @description 获取二维码
         */
        fnGetCode(item){
            let base = this.$baseUrl;
            let ticket = localStorage.getItem('sessionTicket');
            let dist = this.$studentBaseUrl;
            let path = '';

            switch(item.type){
                case 1:
                    path = '/good-detail?goodNo='+item.aim_no;
                    break;
                case 2:
                    path = '/task-detail?id='+item.aim_no;
                    break;
                case 3:
                    path = '/project-detail?project_no='+item.aim_no;
                    break;
                case 4:
                    path = '/part-time-detail?parttime_no='+item.aim_no;
                    break;
                case 5:
                    path = '/internship-detail?internship_no='+item.aim_no;
                    break;
                default:
                    this.$message({
                        type: 'warning',
                        message: '暂无地址',
                        center: true,
                        duration: 5000
                    });
                    return '';
            }
            let url = `${base}/__local/common%5Cqrcode?content=${encodeURI(dist+path)}&__ticket=${ticket}`;

            this.$set(item, 'preview_code', url);
        },

        /**
         * @description 设置备注
         */
        fnRemark(item){
            this.$prompt('请输入备注', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /\S/,
                inputErrorMessage: '请输入备注'
            }).then(({ value }) => {
                this.$post('/student/student_complain%5Cremark', {
                    id: item.id,
                    remark: value,
                }, resp => {
                    if(resp.code == 1){
                        this.$set(item, 'remark', value);
                        this.$message({
                            type: 'success',
                            message: '操作成功',
                            center: true
                        });
                    }else{
                        this.$message({
                            type: 'warning',
                            message: resp.msg,
                            center: true,
                            duration: 5000
                        });
                    }
                });
            }).catch(() => {
            });
        },

        /**
         * @description 设置回复
         */
        reReplytoUser(item){
            this.$prompt('请输入要回复用户的信息', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /\S/,
                inputErrorMessage: '请输入备注'
            }).then(({ value }) => {
                this.$post('/student/student_complain%5Creply', {
                    id: item.id,
                    reply_content: value,
                }, resp => {
                    if(resp.code == 1){
                        this.$set(item, 'reply_contentrk', value);
                        this.$message({
                            type: 'success',
                            message: '操作成功',
                            center: true
                        });
                        this.getTableData();
                    }else{
                        this.$message({
                            type: 'warning',
                            message: resp.msg,
                            center: true,
                            duration: 5000
                        });
                    }
                });
            }).catch(() => {
            });
        },

        /**
         * @description 反馈类型
         */
        typeFormatter(row, column, val) {
            if (!val) {
                return '--';
            } else if (val == 1) {
                return '商品';
            } else if (val == 2) {
                return '任务';
            } else if (val == 3) {
                return '校园大使';
            } else if (val == 4) {
                return '兼职';
            } else if (val == 5) {
                return '实习';
            }else {
                return '--';
            }
        },

        /**
         * @description 查看图片
         * @param   {String}    images    单图预览
         * @param   {Array}     images     多图预览
         */
        fnShowPreview(images) {
            if(images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images);
            } else {
                this.$notify({
                    title: '提示',
                    message: '图片类型错误',
                    type: 'warning',
                    duration: 2000
                });
            }
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) {
                return '--';
            }
            return val;
        },

        /**
         * @description 复制
         */
        copyUrl (url) {
            let str = url;
            let oInput = document.createElement("input");

            oInput.value = str;
            document.body.appendChild(oInput);
            oInput.select();
            document.execCommand("Copy");
            oInput.style.display = "none";
            this.$notify({
                title: '提示',
                message: '复制成功',
                type: 'success',
                duration: 2000
            });
        },
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 10px 15px 5px 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 10px;
                white-space: nowrap;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
    // 表格
    .data-table {
        ::-webkit-scrollbar {
            width: 6px;
            height: 6px;
        }

        // 操作按钮
        .option-btn-group {
            .el-button {
                margin-left: 0;
                margin-right: 10px;
            }
        }
    }
</style>
<style lang="less">
    .feedBackUser{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
    }
</style>
